<template>
  <view class="cart-container" style="background-color: #ffffff;" v-if="cart.length !== 0">
    <!-- 收货地址组件 -->
    <my-address></my-address>
    <!-- 标题部分 -->
    <view class="cart-title">
      <!-- 图标 -->
      <uni-icons type="shop" size="22"></uni-icons>
      <!-- 文本 -->
      <text class="title-text">购物车</text>
    </view>
    <!-- 商品列表区域信息 -->
    <uni-swipe-action>
      <block v-for="(item, i) in cart" :key="i">
        <uni-swipe-action-item :right-options="options" @click="swipeHandler(item)">
          <my-goods :goods="item" :isShow="true" :isNum="true" @changeRedio="changeRedio" @changeNum="changeNum"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 结算组件 -->
    <my-settle></my-settle>
  </view>
  <!-- 空白购物车区域 -->
  <view class="empty-cart" v-else>
    <text>目前您还未添加购物车</text>
  </view>
</template>

<script>
  import badegeMi from '@/mixins/tabbar-badge.js'
  import { mapState, mapMutations } from 'vuex'

  export default {
    data() {
      return {
        options: [
          {
            text: '删除',
            style: {
                backgroundColor: '#c00000'
            }
        }
        ]
      };
    },
    // 使用mixins混入
    mixins: [badegeMi],
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    methods: {
      ...mapMutations('m_cart', ['updataGoodsState','updateGoodsNum','removeGoods']),
      // 接收复选框的属性
      changeRedio(e) {
        this.updataGoodsState(e)
      },
      // 接收传递过来的商品数量值
      changeNum(e) {
        console.log(e);
        this.updateGoodsNum(e)
      },
      // 点击滑动删除
      swipeHandler(goods) {
        console.log(goods);
        this.removeGoods(goods)
      }
    }
    
  }
</script>

<style lang="scss" scoped>
.cart-container{
  padding-bottom: 50px;
}
.cart-title{
  height: 40px;
  padding-left: 10px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ccc;
  .title-text{
    font-size: 14px;
    margin-left: 10px;
  }
}
.empty-cart{
  width: 100%;
  text-align: center;
  margin-top: 100px;
}
</style>
